import { constantRoutes, asyncRoutes } from '@/router'
import { list2Tree, tarn2Routes } from '@/utils'
export default {
  namespaced: true,
  state() {
    return {
      routes: [...constantRoutes]
    }
  },
  getters: {},
  mutations: {
    // 设置完整信息
    setRoutes(state, data) {
      // data 是用户的动态路由
      state.routes = [...constantRoutes, ...data]
    }
  },
  actions: {
    filterRoutes(store, menuMarks) {
      console.log('menuMarks:', menuMarks)
      console.log('asyncRoutes:', asyncRoutes)
      const userAsyncRoutes = tarn2Routes(list2Tree(menuMarks, 0))
      console.log('userAsyncRoutes:', userAsyncRoutes)
      userAsyncRoutes.push({ path: '*', redirect: '/404', hidden: true })
      store.commit('setRoutes', userAsyncRoutes)
      return userAsyncRoutes
    }
  }
}
